package org.javia.arity;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class MoreMathTest {

	double a=12.345;
	double delta=0.0001;
	
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAsinh() {
		assertEquals(3.2080347119330812,MoreMath.asinh(a),delta);
		assertEquals(-3.2080347119330812,MoreMath.asinh(-a),delta);
		
	}

	@Test
	public void testAcosh() {
		assertEquals(3.2047538216182560,MoreMath.acosh(a),delta);
	}

	@Test
	public void testAtanh() {
		assertEquals(0.359757028200343,MoreMath.atanh(0.345),delta);
		assertEquals(-0.359757028200343,MoreMath.atanh(-0.345),delta);
	}

	@Test
	public void testTrunc() {
		assertEquals((int)a,MoreMath.trunc(a),0);
		assertEquals(-(int)a,MoreMath.trunc(-a),0);
	}

	@Test
	public void testGcd() {
		assertEquals(3,MoreMath.gcd(3, 6),delta);
		assertEquals(Double.NaN,MoreMath.gcd(Double.NaN, 6),delta);
	}

	@Test
	public void testLgamma() {
		assertEquals(20.863398103090333,MoreMath.lgamma(a),delta);
	}

	@Test
	public void testFactorial() {
		assertEquals(6,MoreMath.factorial(3),delta);
		assertEquals(Double.NaN,MoreMath.factorial(-3),delta);
		assertEquals(1,MoreMath.factorial(0),delta);
		//assertEquals(0,MoreMath.factorial(171),delta);
	}

	@Test
	public void testCombinations() {
		assertEquals(1.0003130826430864,MoreMath.combinations(a, delta),delta);
		assertEquals(Double.NaN,MoreMath.combinations(-a, delta),delta);
		assertEquals(0,MoreMath.combinations(0, 1),delta);
		assertEquals(1,MoreMath.combinations(2, 2),delta);
		assertEquals(14535,MoreMath.combinations(171, 2),delta);
		assertEquals(1.5511751999999997E8,MoreMath.combinations(30, 15),delta);
	}

	@Test
	public void testPermutations() {
		assertEquals(Double.NaN,MoreMath.permutations(-1, 2),delta);
		assertEquals(0,MoreMath.permutations(2, 3),delta);
		assertEquals(2,MoreMath.permutations(2, 2),delta);
		assertEquals(2.92222,MoreMath.permutations(2.33, 2.22),delta);
		assertEquals(2.0284320493172733E20,MoreMath.permutations(30, 15),delta);
	}

	@Test
	public void testLog2() {
		assertEquals(3,MoreMath.log2(8),delta);
	}

	@Test
	public void testSin() {
		assertEquals(0.841471,MoreMath.sin(1),delta);
		assertEquals(0,MoreMath.sin(Math.PI),delta);
	}

	@Test
	public void testCos() {
		assertEquals(1,MoreMath.cos(0),delta);
		assertEquals(0,MoreMath.cos(3*Math.PI/2),delta);
	}

	@Test
	public void testTan() {
		assertEquals(0.546302,MoreMath.tan(0.5),delta);
		assertEquals(0,MoreMath.tan(Math.PI),delta);
	}

	@Test
	public void testIntLog10() {
		assertEquals(4,MoreMath.intLog10(10000),delta);
	}

	@Test
	public void testIntExp10() {
		assertEquals(1E10,MoreMath.intExp10(10),delta);
	}

}
